package com.bs.sc.front.goodsCar.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bs.sc.base.utils.AjaxJson;
import com.bs.sc.front.goodsCar.service.GoodsCarService;

@RestController
@RequestMapping(value = "/goodsCar")
@CrossOrigin
public class GoodsCarController {

	@Autowired
	private GoodsCarService goodsCarService;

	/**
	 * 在购物车改变商品数量
	 * 
	 * @param request
	 * @param goodsId
	 * @param count
	 * @return
	 */
	@RequestMapping(value = "changeGoodsNumber", method = RequestMethod.POST)
	public AjaxJson changeGoodsNumber(HttpServletRequest request, String goodsId, int count) {
		return goodsCarService.goodsCarService(request, goodsId, count);
	}

	/**
	 * 添加购物车
	 * 
	 * @param request
	 * @param goodsId
	 * @return
	 */
	@RequestMapping(value = "addGoodsCar", method = RequestMethod.POST)
	public AjaxJson addGoodsCar(HttpServletRequest request, String goodsId) {
		return goodsCarService.addGoodsCar(request, goodsId);
	}

	/**
	 * 获取购物车数据
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "getCarGoods", method = RequestMethod.POST)
	public AjaxJson getCarGoods(HttpServletRequest request) {
		return goodsCarService.getCarGoods(request);
	}

	/**
	 * 删除购物车商品
	 * 
	 * @param itemId
	 * @param carId
	 * @return
	 */
	@RequestMapping(value = "deleteCarItem", method = RequestMethod.POST)
	public AjaxJson deleteCarItem(String itemId, String carId) {
		return goodsCarService.deleteCarItem(itemId, carId);
	}
}
